package com.wisdytech.linkdcs.tool.action;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.system.model.SysUser;
import com.wisdytech.linkdcs.tool.model.ToolRepair;
import com.wisdytech.linkdcs.tool.service.IToolRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/tool/repair")
public class ToolRepairAction {

    @Resource
    private IToolRepairService repairService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
     *
     * <p>Description: 工装检验</p>
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolRepairIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "tool/toolRepair";
    }

    @RequestMapping(value = "/getToolRepairByFilter/get.mvc")
    @ResponseBody
    public StandardTableResult<ToolRepair> getToolRepairByFilter(String toolCode, String toolName, String toolType, String toolModel,String toolStatus, String equipCode , Filter filter) {
        PageInfo<ToolRepair> page = repairService.getToolRepairByFilter(toolCode,toolName,toolType,toolModel,toolStatus,equipCode,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    /**
     * 维修接口
     * @param toolRepair 实体类
     * @return StandardResult
     */
    @RequestMapping(value = "/repair/save.mvc")
    @ResponseBody
    public StandardResult repair(ToolRepair toolRepair) {
        SysUser user = BaseUtil.getCurrentUser();
        this.repairService.repair(toolRepair,user);
        return StandardResult.getSuccessResult();
    }

    /**
     * 送修接口
     * @param toolRepair 实体类
     * @return StandardResult
     */
    @RequestMapping(value = "/sendRepair/save.mvc")
    @ResponseBody
    public StandardResult sendRepair(ToolRepair toolRepair) {
        SysUser user = BaseUtil.getCurrentUser();
        this.repairService.sendPepair(toolRepair,user);
        return StandardResult.getSuccessResult();
    }

    /**
     * 维修接口
     * @param toolCodes 需要报废的工装编码
     * @return StandardResult
     */
    @RequestMapping(value = "/scrap/save.mvc")
    @ResponseBody
    public StandardResult scrap(String toolCodes) {
        SysUser user = BaseUtil.getCurrentUser();
        this.repairService.scrap(toolCodes,user);
        return StandardResult.getSuccessResult();
    }

    /**
     * 维修接口
     * @param toolCodes 需要返厂的工装编码
     * @param pkIds 需要更新返厂时间的维修记录id
     * @return StandardResult
     */
    @RequestMapping(value = "/backFactory/save.mvc")
    @ResponseBody
    public StandardResult backFactory(String toolCodes,String pkIds) {
        SysUser user = BaseUtil.getCurrentUser();
        this.repairService.backFactory(toolCodes,pkIds,user);
        return StandardResult.getSuccessResult();
    }



}
